import request from "@/utils/request";

class articleAPI {
  static getArticle(params?: ArticleData) {
    return request<any, PageResult<ArticleResult[]>>({
      url: "/docs",
      method: "get",
      params,
    });
  }

  static addArticle(data?: ArticleResult) {
    return request<any, null>({
      url: "/docs",
      method: "put",
      data,
    });
  }

  static deleteArticle(data: articleId) {
    return request<any, null>({
      url: `/docs/${data.id}`,
      method: "delete",
      data,
    });
  }

  static editArticle(data: ArticleResult) {
    return request<any, null>({
      url: "/docs",
      method: "post",
      data,
    });
  }

  static getByIdArticle(params: articleId) {
    return request<any, ArticleResult[]>({
      url: `/docs/${params.id}`,
      method: "get",
      params,
    });
  }

  static putArticlePicture(data: putArticlePicture) {
    return request<any, number>({
      url: "/putArticlePicture",
      method: "put",
      data,
    });
  }

  static putArticleVedio(data?: putArticleVedio) {
    return request<any, number>({
      url: "/putArticleVedio",
      method: "put",
      data,
    });
  }
}

export default articleAPI;

export interface ArticleData {
  categoryid?: number;
  author?: string;
  heading?: string;
  readTime?: number;
  page?: number;
  pageSize?: number;
}

export interface ArticleResult {
  id: number;
  cover: string;
  heading: string;
  content: string;
  articlePicture: number;
  articleVedio: number;
  categoryId: number;
  readTime?: number;
  author: string;
  uploadTime?: string;
  lastModifyTime?: string;
}

export interface articleId {
  id: number;
}

export interface putArticlePicture {
  image: File;
}

export interface putArticleVedio {
  Vedio?: File;
}
